import '../helper/Helper.dart';
import '../helper/dioHelper.dart';

class Station {
  int ID;
  String Guid;
  String STNM;
  String STCD;
  String STTP;
  double LTTD;
  double LGTD;
  String River;
  String Collection;
  String Location;
  int Code;
  int State;
  String DuanXin;
  String WeiXing;
  String ManaName;
  String ManaPhone;
  String BuildTime;
  String Remark;

  Station(
      this.ID,
      this.Guid,
      this.STNM,
      this.STCD,
      this.STTP,
      this.LTTD,
      this.LGTD,
      this.River,
      this.Collection,
      this.Location,
      this.Code,
      this.State,
      this.DuanXin,
      this.WeiXing,
      this.ManaName,
      this.ManaPhone,
      this.BuildTime,
      this.Remark);
  Station.fromJson(Map<String, dynamic> json)
      : ID = json["ID"],
        Guid = json["Guid"],
        STNM = json["STNM"],
        STCD = json["STCD"],
        STTP = json["STTP"],
        LTTD = json["LTTD"],
        LGTD = json["LGTD"],
        River = json["River"],
        Collection = json["Collection"],
        Location = json["Location"],
        Code = json["Code"],
        State = json["State"],
        DuanXin = json["DuanXin"],
        WeiXing = json["WeiXing"],
        ManaName = json["ManaName"],
        ManaPhone = json["ManaPhone"],
        BuildTime = json["BuildTime"],
        Remark = json["Remark"];
  Map<String, dynamic> toJson() => {
        'ID': ID,
        'Guid': Guid,
        'STNM': STNM,
        'STCD': STCD,
        'STTP': STTP,
        'LTTD': LTTD,
        'LGTD': LGTD,
        'River': River,
        'Collection': Collection,
        'Location': Location,
        'Code': Code,
        'State': State,
        'DuanXin': DuanXin,
        'WeiXing': WeiXing,
        'ManaName': ManaName,
        'ManaPhone': ManaPhone,
        'BuildTime': BuildTime,
        'Remark': Remark,
      };
  static Future<bool> Add(Station x1) async {
    var response = await DioHelper.Post("/Station/Add", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<bool> Update(Station x1) async {
    var response = await DioHelper.Post("/Station/Update", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<bool> Delete(Station x1) async {
    var st = x1.toJson();
    var response = await DioHelper.Post("/Station/Delete", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<Station?> Get(String where, dynamic data) async {
    var response = await DioHelper.Post("/Station/GetByWhere", {
      "Where": where,
      "obj": data,
    });

    if (response.statusCode == 200) return new Station.fromJson(response.data);
    return null;
  }

  static Future<List<Station>> GetList(
      String where, dynamic data, int pageIndex, int pageSize) async {
    var response = await DioHelper.Post("/Station/GetListByWhere", {
      "Where": where,
      "obj": data,
      "PageIndex": pageIndex,
      "PageSize": pageSize,
    });
    var list1 = <Station>[];
    if (response.statusCode == 200) {
      for (var x in response.data) {
        list1.add(new Station.fromJson(x));
      }
    }
    return list1;
  }

  static Future<List<Station>> GetAllList() async {
    var response = await DioHelper.Get("/Station/GetList", {});
    var list1 = <Station>[];
    if (response.statusCode == 200) {
      for (var x in response.data) {
        list1.add(new Station.fromJson(x));
      }
    }
    return list1;
  }
}
